<?php $show_header = $show_validator = $show_scroll = 1; include $this->admin_tpl('header', 'admin');?>
<link href="<?php echo JS_PATH?>swfupload/swfupload.css" rel="stylesheet" type="text/css" />
<script language="JavaScript" type="text/javascript" src="<?php echo JS_PATH?>swfupload/swfupload.js"></script>
<script language="JavaScript" type="text/javascript" src="<?php echo JS_PATH?>swfupload/fileprogress.js"></script>
<script language="JavaScript" type="text/javascript" src="<?php echo JS_PATH?>swfupload/handlers.js"></script>
<script type="text/javascript">
var swfu = '';
$(document).ready(function(){
swfu = new SWFUpload({
	flash_url:"<?php echo JS_PATH; ?>swfupload/swfupload.swf?"+Math.random(),
	upload_url:"<?php echo APP_PATH; ?>index.php?m=attachment&c=attachments&a=batchUpload&dosubmit=1&pc_hash=<?php echo $this->pc_hash; ?>",
	file_post_name : "Filedata",
	post_params:{"SWFUPLOADSESSID":"<?php echo SYS_TIME; ?>","module":"content","catid":"<?php echo $category['catid'];?>","userid":"<?php echo $this->userid;?>","username":"<?php echo $this->admin_username; ?>","siteid":"<?php echo $siteid;?>","dosubmit":"1","thumb_width":"0","thumb_height":"0","watermark_enable":"0","filetype_post":"jpg|jpeg|gif|png|bmp","swf_auth_key":"<?php echo md5(pc_base::load_config('system','auth_key').SYS_TIME);?>","isadmin":"<?php echo $this->isadmin;?>","groupid":"<?php echo $this->groupid;?>","bids":""},
	file_size_limit:"2048",
	file_types:"*.jpg;*.jpeg;*.gif;*.png;*.bmp",
	file_types_description:"All Files",
	file_upload_limit:"100",
	custom_settings : {progressTarget : "fsUploadProgress",cancelButtonId : "btnCancel"},

	button_image_url: "",
	button_width: 75,
	button_height: 28,
	button_placeholder_id: "buttonPlaceHolder",
	button_text_style: "",
	button_text_top_padding: 3,
	button_text_left_padding: 12,
	button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
	button_cursor: SWFUpload.CURSOR.HAND,

	file_dialog_start_handler : fileDialogStart,
	file_queued_handler : fileQueued,
	file_queue_error_handler:fileQueueError,
	file_dialog_complete_handler:fileDialogComplete,
	upload_progress_handler:uploadProgress,
	upload_error_handler:uploadError,
	upload_success_handler:uploadSuccess,
	upload_complete_handler:uploadComplete,

	debug: true	
	});
})
</script>
<div class="pad-10">
    <div class="col-tab">
        <ul class="tabBut cu-li">
            <li id="tab_swf_1"><?php echo $category['catname']; ?> 批量上传</li>
        </ul>
         <div id="div_swf_1" class="content pad-10">
        	<div>
				<div class="addnew" id="addnew">
					<span id="buttonPlaceHolder"></span>
				</div>
				<input type="button" id="btupload" value="开始上传" onClick="uploadSubmit();" />
                <div id="nameTip" class="onShow">最多上传<font color="red"> 100</font> 个附件,单文件最大 <font color="red">2 MB</font></div>
                <div class="bk3"></div>
				
                <div class="lh24">支持 <font style="font-family: Arial, Helvetica, sans-serif">jpg、jpeg、gif、png、bmp</font> 格式。</div><input type="checkbox" id="watermark_enable" value="1"  onclick="change_params()"> 是否添加水印        
                <?php if ($brand_1) {?>
	                <br />品牌选择<select name="brand_1" id="brand_1">
	                	<?php foreach($brand_1 AS $b1) {
	                		echo "<option value='".$b1['id']."'>".$b1['name']."</option>";
	                	}?>
	                </select><select name="brand_2" id="brand_2" <?php echo ($brand_1[0]['child'] ? "":"style='display:none;'")?>>
	                <?php foreach($brand_1[0]['child'] AS $b2) {
	                		echo "<option value='".$b2['id']."'>".$b2['name']."</option>";
	                	}?>
	                </select>
	             <?php } else{ ?>
	            <br /><span class="red"> 此栏目暂时没有品牌信息</span>
	             <?php }?> 
        	</div> 	
    		<div class="bk10"></div>
        	<fieldset class="blue pad-10" id="swfupload">
        	<legend>列表</legend>
        	<ul class="attachment-list"  id="fsUploadProgress">    
        	</ul>
    		</fieldset>
    	</div>
    <div id="att-status" class="hidden"></div>
     <div id="att-status-del" class="hidden"></div>
    <div id="att-name" class="hidden"></div>
<!-- swf -->
</div>
</body>
<script type="text/javascript"><!--
var brands = <?php echo $brands_json; ?>;
$(function(){
	if(brands){
		$("#brand_1").change(function(){
			var bid_1 = this.value;
			var html="";
			for(i in brands) {
				if(brands[i].id == bid_1) {
					for(j in brands[i].child) {
						html += "<option value='"+brands[i].child[j].id+"'>"+brands[i].child[j].name+"</option>";
					}
					if(html=="") {
						$("#brand_2").html(html).hide();
					}else {
						$("#brand_2").show().html(html);
					}
				}
			}
		});
	}
});

function uploadSubmit()
{
	if($("#brand_1").size() > 0) {
		if($("#brand_2").val()) {
			swfu.addPostParam('bids', $("#brand_1").val()+','+$("#brand_2").val());
		}else {
			swfu.addPostParam('bids', $("#brand_1").val());
		}
		
	}
	
	swfu.startUpload();
}
</script>
<script type="text/javascript">
function imgWrap(obj){
	$(obj).hasClass('on') ? $(obj).removeClass("on") : $(obj).addClass("on");
}

function SwapTab(name,cls_show,cls_hide,cnt,cur) {
    for(i=1;i<=cnt;i++){
		if(i==cur){
			 $('#div_'+name+'_'+i).show();
			 $('#tab_'+name+'_'+i).addClass(cls_show);
			 $('#tab_'+name+'_'+i).removeClass(cls_hide);
		}else{
			 $('#div_'+name+'_'+i).hide();
			 $('#tab_'+name+'_'+i).removeClass(cls_show);
			 $('#tab_'+name+'_'+i).addClass(cls_hide);
		}
	}
}

function addonlinefile(obj) {
	var strs = $(obj).val() ? '|'+ $(obj).val() :'';
	$('#att-status').html(strs);
}

function change_params(){
	if($('#watermark_enable').attr('checked')) {
		swfu.addPostParam('watermark_enable', '1');
	} else {
		swfu.removePostParam('watermark_enable');
	}
}
function set_iframe(id,src){
	$("#"+id).attr("src",src); 
}
function album_cancel(obj,id,source){
	var src = $(obj).children("img").attr("path");
	var filename = $(obj).attr('title');
	if($(obj).hasClass('on')){
		$(obj).removeClass("on");
		var imgstr = $("#att-status").html();
		var length = $("a[class='on']").children("img").length;
		var strs = filenames = '';
		$.get('index.php?m=attachment&c=attachments&a=swfupload_json_del&aid='+id+'&src='+source+'&filename='+filename);
		for(var i=0;i<length;i++){
			strs += '|'+$("a[class='on']").children("img").eq(i).attr('path');
			filenames += '|'+$("a[class='on']").children("img").eq(i).attr('title');
		}
		$('#att-status').html(strs);
		$('#att-status').html(filenames);
	} else {
		var num = $('#att-status').html().split('|').length;
		var file_upload_limit = '<?php echo $file_upload_limit?>';
		if(num > file_upload_limit) {alert('<?php echo L('attachment_tip1')?>'+file_upload_limit+'<?php echo L('attachment_tip2')?>'); return false;}
		$(obj).addClass("on");
		$.get('index.php?m=attachment&c=attachments&a=swfupload_json&aid='+id+'&src='+source+'&filename='+filename);
		$('#att-status').append('|'+src);
		$('#att-name').append('|'+filename);
	}
}
</script>
</html>
